package com.woniuxy.amusementparkos.service.xxy.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.amusementparkos.dao.xxy.OrderDao;
import com.woniuxy.amusementparkos.entity.xxy.Order;
import com.woniuxy.amusementparkos.entity.xxy.Order_Item;
import com.woniuxy.amusementparkos.exception.xxy.SelectException;
import com.woniuxy.amusementparkos.service.xxy.OrderService;
@Service
public class OrderServiceImpl implements OrderService {
	@Autowired
	OrderDao orderDao;
	//根据商店id查询商店所有的订单
	@Override
	public List<Order> selectOrdersByStore_id(int store_id,int page,int pageSize) {
		try {
			 return orderDao.selectOrdersByStore_id(store_id, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		}
	}
	//根据商店id查询商店所有的订单数量
	@Override
	public long selectOrdersCountByStore_id(int store_id) {
		try {
			return orderDao.selectOrdersCountByStore_id(store_id);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		}
	}
	//通过uuid查订单所有的订单条目
	@Override
	public List<Order_Item> selectOrder_itemByUuid(String uuid) {
		try {
			return orderDao.selectOrder_itemByUuid(uuid);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		}

	}
	//通过uuid查订单所有的订单条目数量
	@Override
	public long selectOrder_itemCountByUuid(String uuid) {
		try {
			return orderDao.selectOrder_itemCountByUuid(uuid);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		}
	}
	//通过uuid查询订单
	@Override
	public Order selectOrderByUUID(String uuid) {
		try {
			return orderDao.selectOrderByUUID(uuid);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		}
	}
	//添加订单条目
	@Override
	public void insertOrder_item(Order_Item order_item) {
		try {
			orderDao.insertOrder_item(order_item);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		}
		
	}
	//添加订单
	@Override
	public void insertOrder(Order order) {
		try {
			orderDao.insertOrder(order);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		}
		
	}
	@Override
	public Order selectOrderInfoByUuid(String uuid) {
		try {
			return orderDao.selectOrderInfoByUuid(uuid);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		}
	}
	@Override
	public List<Order> selectAllOrders(int page, int pageSize) {
		try {
			return orderDao.selectAllOrders(page, pageSize);
			
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		}
	}
	@Override
	public long selectAllOrdersCount() {
		try {
			return orderDao.selectAllOrdersCount();
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("查询错误,请联系管理员");
		} 
	}
	@Override
	public void updateOrderStateByUUID(String uuid) {
		try {
			orderDao.updateOrderStateByUUID(uuid);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SelectException("更新订单状态失败,请联系管理员");
		}
		
	}
}
